local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__ArrayIndexOf = ____lualib.__TS__ArrayIndexOf
local __TS__ArraySplice = ____lualib.__TS__ArraySplice
local __TS__SourceMapTraceBack = ____lualib.__TS__SourceMapTraceBack
__TS__SourceMapTraceBack(debug.getinfo(1).short_src, {["9"] = 3,["10"] = 3,["11"] = 4,["12"] = 4,["13"] = 5,["14"] = 5,["15"] = 7,["16"] = 7,["17"] = 11,["18"] = 14,["19"] = 22,["20"] = 24,["21"] = 24,["22"] = 24,["23"] = 24,["24"] = 28,["25"] = 24,["26"] = 30,["27"] = 31,["28"] = 32,["29"] = 33,["30"] = 35,["31"] = 35,["32"] = 35,["33"] = 36,["36"] = 39,["37"] = 40,["38"] = 41,["39"] = 42,["40"] = 43,["42"] = 45,["43"] = 46,["44"] = 47,["45"] = 48,["46"] = 49,["47"] = 49,["48"] = 49,["49"] = 50,["50"] = 51,["51"] = 52,["53"] = 54,["54"] = 55,["55"] = 49,["56"] = 49,["57"] = 49,["58"] = 35,["59"] = 35,["60"] = 28,["61"] = 64,["62"] = 65,["63"] = 66,["64"] = 67,["65"] = 68,["68"] = 71,["69"] = 72,["70"] = 73,["71"] = 74,["75"] = 82,["78"] = 77,["79"] = 78,["80"] = 80,["86"] = 64,["87"] = 89,["88"] = 90,["89"] = 89});
local ____exports = {}
local ____event_util = require("kernel.util.event_util")
local EventUtil = ____event_util.default
local ____AbstractData = require("kernel.interfaces.AbstractData")
local AbstractData = ____AbstractData.default
local ____ui = require("kernel.util.ui")
local KUi = ____ui.default
local ____ui = require("data.ui.index")
local UI = ____ui.default
local uiList = {}
local posList = {1804, 1612.33, 1420.67, 1229}
local sorts = {}
____exports.default = __TS__Class()
local ReviveController = ____exports.default
ReviveController.name = "ReviveController"
__TS__ClassExtends(ReviveController, AbstractData)
function ReviveController.prototype.____constructor(self, unit)
    AbstractData.prototype.____constructor(self)
    self.unit = unit
    local path = UI.HeroRevive[unit.owner.id]
    self.ui = KUi:searchPath(unit.owner, path)
    uiList[#uiList + 1] = self.ui
    EventUtil:register(
        "UNIT_DIE",
        function(data)
            if data.__unit_id ~= self.unit.id then
                return
            end
            local val = unit:getData("revive_time", 5)
            local deathCount = unit:getData("revive_count", 0)
            val = val + deathCount * 3
            if val >= 30 then
                val = 30
            end
            self.ui.parent:visible(true)
            self:refreshUI(val)
            deathCount = deathCount + 1
            unit:setData("revive_count", deathCount)
            local timerId
            timerId = setInterval(
                function()
                    if val <= 0 then
                        unit:revive(Fix32Vec3(0, 0, 0))
                        clearInterval(timerId)
                    end
                    self:refreshUI(val)
                    val = val - 1
                end,
                1000
            )
        end
    )
end
function ReviveController.prototype.refreshUI(self, val)
    local sort = __TS__ArrayIndexOf(sorts, self.ui.id)
    if val <= 0 then
        __TS__ArraySplice(sorts, sort, 1)
        self.ui.parent:visible(false)
        return
    end
    local pos = #sorts
    if sort == -1 or pos == 0 then
        sorts[#sorts + 1] = self.ui.id
        pos = 1
    end
    do
        local function ____catch(e)
            ____print(e)
        end
        local ____try, ____hasReturned = pcall(function()
            local left = self:getLeftPos(pos)
            self.ui:setText(("剩余" .. tostring(val)) .. "秒复活")
            ____print(("剩余" .. tostring(val)) .. "秒复活")
        end)
        if not ____try then
            ____catch(____hasReturned)
        end
    end
end
function ReviveController.prototype.getLeftPos(self, size)
    return posList[size]
end
return ____exports
